var SysRolePage = {
	'refreshMenu':function() {
		menuTree.refresh(true);
	},
	'onQuerySucc':function(data, xhr, status) {
		
	},
	'onItemClick':function(index,item) {
		 // alert("index = " + index + ", item = " + JSON.stringify(item));
		var currItem = roleDatatable.getCurrentItem();
		if (currItem == null) {
			return ;
		}
		var roleId = null;
		if (currItem != null) {
			roleId = currItem.roleId;
		} else {
			roleId = "empty";
		}
		// 判断当前选中是否与先前选中一致，
		//     若一致，则忽略，不请求新菜单，exit
		//     若不一致，则判断当前角色菜单是否发生变化
		//         若发生变化，则提示保存，exit
		//         若未发生变化，切换触发器，请求刷新页面，exit
		var triggerRecorder = menuTree.getTriggerRecorder();
		if (triggerRecorder.isSelfTrigger(roleId)) {
			return ;
		} else {
			if (triggerRecorder.hasChanged()) {
				// MsgBox.confirm("角色菜单已变更，请先保存该角色菜单");
				SysRolePage.saveRelation();
			}
		}
		triggerRecorder.switchTrigger(roleId);
		
		findMenusByRoleIdAjax.tempUrl(function(url){
			return url + roleId; 
		});
		$("#currentRole").text(currItem.roleName);	
		findMenusByRoleIdAjax.send();
	},
	// 保存角色菜单关联关系
	'saveRelation':function() {
		var triggerRecorder = menuTree.getTriggerRecorder();
		var roleId = triggerRecorder.getTriggerId();
		saveRelationAjax.tempUrl(function(url) {
			return url + roleId;
		});
		saveRelationAjax.setData({
			'menuIds':menuTree.getCheckedNodeIds()
		});
		saveRelationAjax.send();
		$.messager.info("正在保存角色菜单");
	},
	'saveRelationSucc':function(data,status,xhr) {
		$.messager.info("保存角色菜单成功");
	},
	'queryByCondition':function() {
		findRolesAjax.send();
	},
	'openRoleAddDialog':function() {
		MsgBox.open("roleAdd","新增角色",ctx + "/sys/role/index/add","550px");
	},
	// findMenusByRoleIdAjax 根据角色ID查询菜单成功回调
	'onQueryMenusSucc':function(data, status, xhr) {
		menuTree.checkNodesWithIdArray($.toPropertyValueArray(data.info, "resId"));
	},
	// 打开修改角色信息对话框
	'openRoleUpdateDialog':function(item, e) {
		MsgBox.open("roleUpdate","修改角色",ctx + "/sys/role/index/update/" + item.roleId,"550px");
	},
	'deleteRole':function(item, e) {
		MsgBox.confirm("确定删除角色：" + item.roleName, null, function(){
			var roleId = item.roleId;
			// alert("要删除的角色的ID为： " + JSON.stringify(item));
			deleteRoleAjax.tempUrl(function(url){
				return url + roleId;
			});
			deleteRoleAjax.send();
		});
	},
	'onDeleteSucc':function(data, xhr, status) {
		MsgBox.info(data.message, null, function() {
			roleDatatable.refresh();
		});
	}
};